/**
 * 编码：GBK
 * 
 */
var PCDialog = {
    title: "提示",
    content: "内容",
    width: "400",
    height: "200",
    isTab: false,
    css: "",
    inited: false,
    drawing: false,
    callbackFn: null,
    initPage: function() {
        if (!this.inited) {
            var temp_float = new String();
            temp_float = "<div id=\"floatBoxBg\" style=\"height:" + jQuery(document).height() + "px;filter:alpha(opacity=50);opacity:0.5;\"></div>";
            temp_float += "<div id=\"floatBox\" class=\"floatDiv\" style=\"width:" + this.width + "px;\"><div class=\"bgFilter\">";
            temp_float += "<div id=\"conBox\" class=\"conBox\">";
            if (!this.istab && this.title != "") {
                temp_float += "<div class=\"fTit\"><span class=\"fmark\">提示</span><a href=\"javascript:void(0);\" onFocus=\"this.blur();\"  class=\"fclose\"></a></div>";
            }
            temp_float += "<div class=\"iframeBox\"></div>";
            temp_float += "</div></div></div>";
            jQuery("body").append(temp_float);

            // jQuery("#floatBox").jqDrag(".fTit");
            jQuery("#floatBox .fTit .fclose").bind("click",
            function(event) {
                event.stopPropagation();
                PCDialog.hide();
            });
            this.inited = true;
        }

    },
    open: function(title, content, width, height, callback, css, istab) {
        this.title = title;
        if (typeof(content) == "string") this.content = content;
        if (typeof(width) == "string") this.width = width;
        if (typeof(height) == "string") this.height = height;
        if (typeof(callback) == "function") this.callbackFn = callback;
        if (typeof(css) == "string") this.css = css;
        if (!css) this.css = "";
        if (typeof(istab) == "boolean") this.istab = istab;
        if (!istab) this.istab = false;
        if (document.all && document.readyState != "complete") return;
        this.show();
    },
    show: function() {
        this.initPage();
        jQuery("#floatBox .fTit .fmark").html(this.title);
        var contentType = this.content.substring(0, this.content.indexOf(":"));
        var content = this.content.substring(this.content.indexOf(":") + 1, this.content.length);
        //jQuery("#floatBox .iframeBox").find("iframe:eq(0)").attr("src","about:blank");
        switch (contentType) {
        case "url":
            var content_array = content.split("?");
            jQuery("#floatBox .floatContent").ajaxStart(function() {
                jQuery(this).html("loading...");
            });
            jQuery.ajax({
                type: content_array[0],
                url: content_array[1],
                data: content_array[2],
                error: function() {
                    jQuery("#floatBox .iframeBox").html("error...");
                },
                success: function(html) {
                    jQuery("#floatBox .iframeBox").html(html);
                }
            });
            break;
        case "text":
            jQuery("#floatBox .iframeBox").html(content);
            break;
        case "id":
            jQuery("#floatBox .iframeBox").html(jQuery("#" + content + "").html());
            break;
        case "iframe":
            var fixH = 42;
            if (this.istab) {
                fixH = 14;
            }
            
            var addH = this.title === "" ? 31 : 0;
            $("#floatIframe").remove();
            
            /*jQuery("#floatBox .iframeBox").html(
                "<iframe src=\""+ content+ "\" id=\"floatIframe\"  name=\"floatIframe\" width=" + (parseInt(this.width) - 10)
                + " height=\"" + (parseInt(this.height) + addH - fixH)
                + "\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");*/
            jQuery("#floatBox .iframeBox").get(0).innerHTML = 
                    "<iframe src=\""+ content+ "\" id=\"floatIframe\"  name=\"floatIframe\" width=" + (parseInt(this.width) - 10)
                    + " height=\"" + (parseInt(this.height) + addH - fixH)
                    + "\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>";
            
            //alert(!!window.ActiveXObject + " && " +  !window.XMLHttpRequest);
            if ( !!window.ActiveXObject && !window.XMLHttpRequest) {
                //alert("iframe load");
                //document.frames('floatIframe').location.reload();
            }
            break;

        default:
            jQuery("#floatBox .iframeBox").html(content);
            break;
        }
        jQuery("#floatBoxBg").show();
        jQuery("#floatBox").show();
        jQuery("#floatBox .bgFilter").css("height", (this.height - 10));
        jQuery("#floatBox").attr("class", "floatDiv " + this.css);
        jQuery("#floatBox").css({
            width: this.width + "px",
            height: this.height + "px"
        });
        jQuery("#floatBox").css("left", ((jQuery(document.body).width()) / 2 - (parseInt(jQuery("#floatBox").width()) / 2)) + "px");
        jQuery("#floatBox").css("top", (getScreenHeight() - (parseInt(jQuery("#floatBox").height()) / 1.6)) + "px");
        jQuery("#floatBox").fadeIn();
    },
    close: function() {
        try {
            jQuery('#floatBox .fTit .fclose').trigger('click');
        } catch(err) {}
    },
    isOpen: function() {
        try {
            if (!this.inited) {
                return false;
            }
            return new Number(jQuery("#floatBoxBg").css("opacity")) > 0;
        } catch(err) {
            return false;
        }
    },
    hide: function() {
        if (typeof(this.callbackFn) == "function") this.callbackFn();
        
        jQuery("#floatBoxBg").hide();
        jQuery("#floatBox").fadeOut(0);
    },
    size: function(h,w){
        if(!!h){
            this.height = h;
        }
        if(!!w){
            this.width = w;
        }
        jQuery("#floatBox").css({
            width: this.width + "px",
            height: this.height + "px"
        });
        jQuery("#floatBox .bgFilter").css("height", (this.height - 10));
        jQuery("#floatIframe").attr("height",(this.height -10-30-5));
    }
}
function getScreenHeight() {
    var h = 0;
    if (typeof(document.documentElement.scrollTop) != "undefinded" && document.documentElement.scrollTop > 0) {
        h = document.documentElement.scrollTop;
    } else if (typeof(document.body.scrollTop) != "undefinded" && document.body.scrollTop > 0) {
        h = document.body.scrollTop;
    }
    return jQuery(window).height() / 2 + h;
}

(function($) {
    $.fn.jqDrag = function(h) {
        return i(this, h, 'd');
    };
    $.fn.jqResize = function(h) {
        return i(this, h, 'r');
    };
    $.jqDnR = {
        dnr: {},
        e: 0,
        drag: function(v) {
            if (M.k == 'd') E.css({
                left: M.X + v.pageX - M.pX,
                top: M.Y + v.pageY - M.pY
            });
            else E.css({
                width: Math.max(v.pageX - M.pX + M.W, 0),
                height: Math.max(v.pageY - M.pY + M.H, 0)
            });
            return false;
        },
        stop: function() {
            E.css('opacity', M.o);
            $(document).unbind('mousemove', J.drag).unbind('mouseup', J.stop);
        }
    };
    var J = $.jqDnR,
    M = J.dnr,
    E = J.e,
    i = function(e, h, k) {
        return e.each(function() {
            h = (h) ? $(h, e) : e;
            h.bind('mousedown', {
                e: e,
                k: k
            },
            function(v) {
                var d = v.data,
                p = {};
                E = d.e;
                // attempt utilization of dimensions plugin to fix IE issues
                if (E.css('position') != 'relative') {
                    try {
                        E.position(p);
                    } catch(e) {}
                }
                M = {
                    X: p.left || f('left') || 0,
                    Y: p.top || f('top') || 0,
                    W: f('width') || E[0].scrollWidth || 0,
                    H: f('height') || E[0].scrollHeight || 0,
                    pX: v.pageX,
                    pY: v.pageY,
                    k: d.k,
                    o: E.css('opacity')
                };
                E.css({
                    opacity: 0.8
                });
                $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
                return false;
            });
        });
    },
    f = function(k) {
        return parseInt(E.css(k)) || false;
    };
})(jQuery);